﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Web.Profile;
using Gift.DAL;
using Gift.Model;

namespace WebSite.cn
{
    public partial class orderlist : BasePage
    {
        readonly DALOrder theOrder = new DALOrder();
        // Fields
        public string ordermsg = "";

        public string DisplayLeft
        {
            get
            {
                if (base.LoginUserMember == null || string.IsNullOrEmpty(base.LoginUserMember.MemberId))
                {
                    return "display:none;";
                }
                else
                {
                    return "";
                }
            }
        }

        public string DisplayRightWidth
        {
            get
            {
                if (base.LoginUserMember == null || string.IsNullOrEmpty(base.LoginUserMember.MemberId))
                {
                    return "width:100%;";
                }
                else
                {
                    return "";
                }
            }
 
        }

        // Methods
        private void Bind()
        {
            string str;
            string str3 = "";
            if (base.LoginUserMember != null && !string.IsNullOrEmpty(base.LoginUserMember.MemberId))
            {
                str = " memberid=" + base.LoginUserMember.MemberId ;
            }
            else
            {
                str = "ordercode='" + base.Request.Form["orderkey"] + "' ";
            }
            DataTable table = theOrder.GetList(str).Tables[0];
            if (table.Rows.Count > 0)
            {
                foreach (DataRow row in table.Rows)
                {
                    this.ordermsg = this.ordermsg + "<tr>";
                    string ordermsg = this.ordermsg;
                    this.ordermsg = ordermsg + "<td height='28' align='center' bgcolor='#FFFFFF'><a href='order.aspx?oid=" + row["orderid"].ToString() + "' target=_self>" + row["ordercode"].ToString() + "</a></td>";
                  
                    if (row["states"].ToString() == "1")
                    {
                        str3 = "备货中";
                    }
                    else if (row["states"].ToString() == "2")
                    {
                        str3 = "已发货";
                    }
                    else if (row["states"].ToString() == "3")
                    {
                        str3 = "已完成";
                    }
                    else if (row["states"].ToString() == "5")
                    {
                        str3 = "已取消";
                    }
                    else if (row["states"].ToString() == "6")
                    {
                        str3 = "<font color='red'>未支付</font>";
                    }
                    else
                    {
                        str3 = "新订单";
                    }

                    this.ordermsg = this.ordermsg + "<td align='center' bgcolor='#FFFFFF'><span class='text_red'><font color='red'>" + str3 + "</font></span></td>";

                    string sCompany = row["sendCompany"].ToString();
                    string sSendDate1 = row["SendDate1"].ToString() == "" ? string.Empty : DateTime.Parse(row["SendDate1"].ToString()).ToString("yyyy-MM-dd HH:mm:ss");
                    if (sSendDate1.Contains("1900-01-01")) sSendDate1 = string.Empty;
                    this.ordermsg = this.ordermsg + "<td align='left' bgcolor='#FFFFFF'><div style='margin:5px; text-align:left;'>物流公司:<span class='text_red'>" + sCompany + "</span> <br />"
                                                       + "物流单号:" + row["sendCode"].ToString() + "<br />"
                                                       + "物流查询网址:<a href='" + row["SendUrl"].ToString() + "' target='_blank'>" + row["SendUrl"].ToString() + "</a><br />"
                                                       + "物流查询电话:" + row["SendTelphone"].ToString() + "<br />"
                                                       + "发货时间:" + sSendDate1 + "<br />";

                    this.ordermsg = this.ordermsg + "</span></div></td></tr>";
                }

            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!base.IsPostBack && ((base.LoginUserMember != null) || (base.Request.Form["orderkey"] != null)))
            {
                this.Bind();
            }
        }

    }
}